<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery.min.js"></script>
</head>
<body>
    <div>
        <h3>猜数字小游戏</h3>
        玩家输入1-10内的一个数字:<input id="num" type="text">
        <p></p>
        <input type="button" value="确认" onclick="selectresultJQ()"> 
        <div id="result_div"></div>
    </div>

    <script>

        function selectresultJQ(){
            var randomNum=1+Math.floor(Math.random()*10);
            var inputnumber=jQuery("#num").val();
            // alert(inputnumber);
            var result;
            if(randomNum==inputnumber)
            {
                result="<h4>猜对了</h4>";
            }
            else
            {
                result="<h4>猜错了,正确的数字是:"+randomNum+"</h4>";
            }
            jQuery("#result_div").html(result);
        }


        function selectresult(){
            var randomNum=1+Math.floor(Math.random()*10);
            var inputnumber=document.getElementById("num");
            var result;
            if(randomNum==inputnumber)
            {
                result="<h4>猜对了</h4>";
            }
            else
            {
                result="<h4>猜错了,正确的数字是:"+randomNum+"</h4>";
            }
            document.getElementById("result_div").innerHTML=result;

        }
    </script>
</body>
</html>